package me.luger.core.commom.init;

import me.luger.core.mvc.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * InitPorperties
 *
 * @author luger
 * @date 2016/8/1 0001
 */
@Order(0)
@Component
public class InitPorperties implements CommandLineRunner {
    @Autowired
    private Environment env;

    @Override
    public void run(String... args) throws Exception {
        Properties prop = new Properties();//属性集合对象
        InputStream in =  getClass().getResourceAsStream("/application.properties");//属性文件流
        prop.load(in);//将属性文件流装载到Properties对象中
        WebService.setProperties(prop);

        String projectName = env.getProperty("project.name");
        WebService.setProjectName(projectName==null?"":projectName);
        String projectBasePath = env.getProperty("project.basePath");
        WebService.setProjectBasePath(projectBasePath==null?"":projectBasePath);
    }
}
